package lesson1;

import java.io.IOException;

import com.sun.tools.javap.JavapTask;

public class RunJavaCompiler {
	
	public static String commonPath = "I:/workspace/projectjava/LiveClass/src/test/java/";
	public static String sourcePath = commonPath + "lesson2/example1/TestGetSetAnnotation.java";
	
	public static String destPath = "I:/workspace/projectjava/LiveClass/output";

	// 在com.sun.tools.javac.main.JavaCompiler的desugar()方法中加入System.out.println()
	public static void main(String args[]) throws IOException {
		compile();
//		decompile();
	}
	
	public static void compile() {
//		javax.tools.JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
//		int rc = compiler.run(null, null, null,
//             new String[]{
//				"-d",destPath,
//				sourcePath
//		     }
//		);
//		System.out.println("Result code: " + rc);

		com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main("javac");
		String[] args = new String[] { 
						    "-sourcepath",".",
							"-d", destPath, 
							sourcePath 
						};
		int rc = compiler.compile(args).exitCode;
		System.out.println("Result code: " + rc);
	}
	
	public static void decompile() {
		String[] args = new String[] { 
		    "-verbose",
		    destPath + "/lesson1/TestClassInitializer.class" 
		};
		JavapTask t = new JavapTask();
        int rc = t.run(args);
        System.exit(rc);
	}

}





